package com.codedancer.campus.mapper;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codedancer.campus.common.core.BaseMapper;
import com.codedancer.campus.po.Plate;
import com.codedancer.campus.qo.plate.PlatePageSearchQo;

public interface PlateMapper extends BaseMapper<Plate> {

    /**
     * 分页查询板块
     *
     * @param platePage
     * @param platePageSearchQo
     * @return
     */
    default IPage<Plate> page2Manager(Page<Plate> platePage, PlatePageSearchQo platePageSearchQo) {
        LambdaQueryWrapper<Plate> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (ObjectUtil.isNotEmpty(platePageSearchQo.getName())) {
            lambdaQueryWrapper.like(Plate::getName, platePageSearchQo.getName());
        }
        lambdaQueryWrapper.orderByDesc(Plate::getCreateTime);
        return selectPage(platePage, lambdaQueryWrapper);
    }
}
